<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title> 开屏广告 </title>
		<style type="text/css">
			html,body{
				padding: 0;
				margin: 0;
			}
			#kaiScreenImg{
				width: 100vw;
				height: 100vh;
			}
			.closeKaiS{
				width: 70px;
				height: 26px;
				color: #FFFFFF;
				background: #251A1A;
				text-align: center;
				border-radius: 14px;
				line-height: 26px;
				opacity: 0.6;
				position: fixed;
				top: 40px;
				right: 20px;
			}
		</style>
	</head>
	<body>
		<div class="contentBox">
			<div class="content" id="privacyContent">
				<img id="kaiScreenImg" src="./test.jpeg" alt="">
				<div class="closeKaiS" onclick="closeKaiS()">
					<span> 跳过 <span>
					<span id="kdownTime" style="margin-left: 8rpx;"> 5s </span>
				</div>
			</div>
		</div>
		
		<!-- 引入广告数据请求地址 -->
		<!-- <script src="../baseUrl.js" type="text/javascript" charset="utf-8"></script> -->
		<!-- 引入uni SDK , 以在原生html中能够调用uni接口 及 plus对象 -->
		<script type="text/javascript" src="../js/webView.js"></script>
		<script type="text/javascript">
			// 从url拿到参数，并转化为对象
			let urlToJsonOpts = (url = window.location.href) => {        // 箭头函数默认传值为当前页面url
			    let obj = {}, 
			        index = url.indexOf('?'), // 看url有没有参数
			        params = url.substr(index + 1); // 截取url参数部分 id = 1 & type = 2
			    if(index != -1) { // 有参数时
			        let parr = params.split('&');  // 将参数分割成数组 ["id = 1 ", " type = 2"]
			        for(let i of parr) {           // 遍历数组
			            let arr = i.split('='); 
			            obj[arr[0]] = arr[1];  
			        }
			    }
			    return obj;  
			}
			let time = urlToJsonOpts().time || 6;
			kdownTime.innerText = time+ 's'
			let timer = null;
			// 获取开屏广告内容
			// (function getPrivacyInfo(){
			// 	fetch(new Request(baseUrl + `/api/open/openscreenpage/getInfo/-1/305`,{
			// 	    method:'get', 
			// 	    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
			// 	})).then(res => res.json())
			// 	.then(res =>{
			// 		res.data? kaiScreenImg.src = res.data.pageUrl : ''
			// 		shutDownTime(time)
			// 	})  
			// })()
			(function chushi(){
				shutDownTime(time)
			})()
			// 广告倒计时
			function shutDownTime(time){
				timer = setInterval(()=>{
					if(time>0){
						time--;
						kdownTime.innerText = time+ 's'
					}else{
						clearInterval(timer) 
					}
				},1000)
			}
			// 关闭广告， 清除定时器，关闭被打开的webview，使用uni接口跳转到app首页
			function closeKaiS(){
				clearInterval(timer) 
				uni.webView.reLaunch({
					url: '/pages/index/index'
				})
				setTimeout(()=>{
					// 关闭当前的webview,并跳转到首页, 延时（防止瞬间的白屏）
					plus.webview.currentWebview().close();
				},100)
			}
		</script>
	</body>
</html>
